﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Web;
using System.Web.DynamicData;
using System.Web.Routing;

namespace BackEnd
{
    public class Global : System.Web.HttpApplication
    {
        private static MetaModel s_defaultModel = new MetaModel();
        public static MetaModel DefaultModel
        {
            get
            {
                return s_defaultModel;
            }
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            DefaultModel.RegisterContext(typeof(Entities), new
            ContextConfiguration()
            {
                ScaffoldAllTables = true
            });


            routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
            {
                Constraints = new RouteValueDictionary(new { action = "List|Details" }),
                Model = DefaultModel
            });


            routes.Add(new DynamicDataRoute("Skill/Insert.aspx")
            {
                Action = PageAction.Insert,
                ViewName = "Insert",
                Model = DefaultModel
            });

            routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
            {
                Constraints = new RouteValueDictionary(new
                {
                    action =
                        "List|Details|Edit|Insert"
                }),
                Model = DefaultModel
            });

        }

        void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes(RouteTable.Routes);
        }

    }
}
